package com.rub.android.jetpack

import android.os.Bundle
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.rub.android.R
import com.rub.android.databinding.ActivityDataBindRecyclerViewBinding
import com.rub.android.jetpack.adapter.RecyclerVidewaAapter
import com.rub.android.jetpack.model.UserIdol

class DataBinding2Activity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //ActivityDataBinding1Binding是databinding控件自动生成的一个类，根据布局名称+Binding生成
        var activityDataBinding = DataBindingUtil.setContentView(
            this,
            R.layout.activity_data_bind_recycler_view
        ) as ActivityDataBindRecyclerViewBinding


        var dataList = ArrayList<UserIdol>()

        for (i in 1..10) {
            dataList.apply {
                add(
                    UserIdol(
                        "蹭蹭$i",
                        "RubRub$i",
                        "https://p1-tt-ipv6.byteimg.com/origin/pgc-image/232843e85a9e49fdb84280207fa23732"
                    )
                )
            }
        }

        //将约束布局(ConstraintLayout)改成线性布局(LinearLayout)
        activityDataBinding.recyclerView.layoutManager = GridLayoutManager(this,1)// LinearLayoutManager(this)
        val adapter = RecyclerVidewaAapter(dataList)
        activityDataBinding.recyclerView.adapter = adapter


    }
}